#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

int cmp(const void* a, const void* b)
{
    return *(int*)a > *(int*)b;
}
bool IsTriangle(int a, int b, int c)
{
    if (b + c > a)
        return true;
    return false;
}
int largestPerimeter(int* nums, int numsSize) {
    qsort(nums, numsSize, sizeof(int), cmp);
    int n1 = numsSize - 1;
    int n2 = numsSize - 2;
    int n3 = numsSize - 3;
    while (n3 >= 0)
    {
        if (IsTriangle(nums[n1], nums[n2], nums[n3]))
            return nums[n1] + nums[n2] + nums[n3];
        else
        {
            n1--;
            n2--;
            n3--;
        }
    }
    return 0;
}